package com.foxzzz.base;


import java.util.regex.Pattern;

public class ListNode {

    public int val;
    public ListNode next;

    public ListNode(int x) {
        val = x;
    }

    //[1,2,4]
    public static ListNode getListNode(String val) {
        String[] split = val.replace("[", "").replace("]", "").split(",");
        ListNode root = new ListNode(Integer.parseInt(split[0]));
        ListNode listNode = root;
        for (int i = 1; i < split.length; i++) {
            listNode.next = new ListNode(Integer.parseInt(split[i]));
            listNode = listNode.next;
        }
        return root;
    }

    public static void visit(ListNode listNode) {
        while (listNode != null) {
            System.out.print(listNode.val + " ");
            listNode = listNode.next;
        }
        System.out.println("");
    }
}
